package club.emergency.wechat.question_collection.operate.consumer.controller;

import club.emergency.wechat.common.response.ResponseEntity;
import club.emergency.wechat.common.utils.JsonConvert;
import club.emergency.wechat.model.question_collection.QuestionCollection;
import club.emergency.wechat.question_collection.operate.consumer.service.QuestionCollectionOperateConsumer;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Create with IntelliJ IDEA
 * Project Name: wechat
 * Package Name: club.emergency.wechat.question_collection.search.consumer.controller
 * Date: 2019/2/21
 *
 * @author: 快乐的小菌菌
 * Description:
 */
@Api("收集试题收藏操作接口")
@RestController
@RequestMapping("/question-collection-operate")
public class QuestionCollectionOperateController {

    private QuestionCollectionOperateConsumer questionCollectionOperateConsumer;

    public QuestionCollectionOperateController(QuestionCollectionOperateConsumer questionCollectionOperateConsumer) {
        this.questionCollectionOperateConsumer = questionCollectionOperateConsumer;
    }

    @ApiOperation("新增试题收藏记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "staffId", value = "人员id", dataType = "long", paramType = "query"),
            @ApiImplicitParam(name = "questionId", value = "试题id", dataType = "long", paramType = "query"),
            @ApiImplicitParam(name = "categoryAlias", value = "试题类型别名", dataType = "string", paramType = "query")
    })
    @PostMapping("/save")
    public ResponseEntity save(
            @RequestParam("staffId") Long staffId,
            @RequestParam("questionId") Long questionId,
            @RequestParam("categoryAlias") String categoryAlias
    ) {
        QuestionCollection questionCollection = new QuestionCollection();
        questionCollection.setStaffId(staffId);
        questionCollection.setQuestionId(questionId);
        questionCollection.setCategoryAlias(categoryAlias);
        return new JsonConvert<ResponseEntity>().jsonDecode(questionCollectionOperateConsumer.save(questionCollection), ResponseEntity.class);
    }

    @ApiOperation("删除试题收藏记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "staffId", value = "人员id", dataType = "long", paramType = "query"),
            @ApiImplicitParam(name = "questionId", value = "试题id", dataType = "long", paramType = "query"),
    })
    @PostMapping("/remove")
    public ResponseEntity remove(
            @RequestParam("staffId") Long staffId,
            @RequestParam("questionId") Long questionId
    ) {
        return new JsonConvert<ResponseEntity>().jsonDecode(questionCollectionOperateConsumer.remove(staffId, questionId), ResponseEntity.class);
    }

}
